{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "c8c97086-02d3-43a7-acc3-d589821c5710",
   "metadata": {},
   "source": [
    "## 1.引入包并添加gdal投影目录"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "d0130c61-dbd0-42c0-be70-17c79d945e60",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import numpy as np\n",
    "from osgeo import gdal, osr\n",
    "\n",
    "# 投影文件位置，注意是相对位置，要根据你自己的虚拟目录进行对应\n",
    "os.environ['PROJ_LIB'] = r'.venv\\Lib\\site-packages\\osgeo\\data\\proj'"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "20c1ac92-395e-4a00-854d-47f10f753a1e",
   "metadata": {},
   "source": [
    "## 2.创建4个随机的一维数组"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "cb9f1101-3431-4c2d-87f7-fb42c82e125d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0.5045208  0.92406741 0.96117996 0.64262153 0.8715444  0.19496945\n",
      " 0.53084609 0.61899516 0.28123388 0.80624643 0.20431289 0.9510875\n",
      " 0.59896979 0.5517332  0.95782439 0.40131312 0.19812512 0.53569954\n",
      " 0.93270243 0.29443461 0.64162742 0.76089355 0.64056177 0.18410004\n",
      " 0.144533  ]\n"
     ]
    }
   ],
   "source": [
    "# 设定一维数组长度\n",
    "array_length = 25\n",
    "\n",
    "# 生成四个一维数组，这里简单使用随机数生成\n",
    "array1 = np.random.rand(array_length)\n",
    "array2 = np.random.rand(array_length)\n",
    "array3 = np.random.rand(array_length)\n",
    "array4 = np.random.rand(array_length)\n",
    "\n",
    "print(array1)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ee32679b-22fb-440f-a622-3af2fbb093fe",
   "metadata": {},
   "source": [
    "## 3.将四个1维数组转为二维数组，并组合成一个2维数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "63aa8f63-3ef8-4986-92a5-fe1ec08c4ad3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[0.5045208  0.92406741 0.96117996 0.64262153 0.8715444 ]\n",
      " [0.19496945 0.53084609 0.61899516 0.28123388 0.80624643]\n",
      " [0.20431289 0.9510875  0.59896979 0.5517332  0.95782439]\n",
      " [0.40131312 0.19812512 0.53569954 0.93270243 0.29443461]\n",
      " [0.64162742 0.76089355 0.64056177 0.18410004 0.144533  ]]\n",
      "-------------\n",
      "[[0.88570355 0.24957787 0.52456327 0.47611231 0.57243493]\n",
      " [0.38154283 0.88163409 0.23039634 0.64221333 0.77179571]\n",
      " [0.19243445 0.49167336 0.94127991 0.82090721 0.24489844]\n",
      " [0.05282288 0.12174842 0.63030444 0.77534971 0.28120104]\n",
      " [0.2435859  0.30837898 0.88005805 0.67591576 0.73206563]]\n",
      "-------------\n",
      "[[0.03656448 0.67389344 0.28020756 0.82800927 0.78491985]\n",
      " [0.87212139 0.86617527 0.13332178 0.35441264 0.57349556]\n",
      " [0.49284138 0.85590938 0.93029303 0.10598924 0.17451217]\n",
      " [0.09894279 0.68081876 0.7936022  0.53810265 0.95868372]\n",
      " [0.13045689 0.25835348 0.03826828 0.66284047 0.81192704]]\n",
      "-------------\n",
      "[[0.08686103 0.17896087 0.88516625 0.83477802 0.83730887]\n",
      " [0.69518642 0.97015567 0.35355177 0.81568589 0.79617097]\n",
      " [0.37924665 0.58746471 0.64707012 0.02160775 0.69610958]\n",
      " [0.33332549 0.55916759 0.53474614 0.91756406 0.63706331]\n",
      " [0.98207718 0.03414705 0.38032678 0.67348959 0.36610101]]\n"
     ]
    }
   ],
   "source": [
    "# 将一维数组转换为二维数组，这里以转换为5×5的二维数组为例\n",
    "two_d_array1 = array1.reshape(5, 5)\n",
    "two_d_array2 = array2.reshape(5, 5)\n",
    "two_d_array3 = array3.reshape(5, 5)\n",
    "two_d_array4 = array4.reshape(5, 5)\n",
    "\n",
    "print( two_d_array1)\n",
    "print('-------------')\n",
    "print( two_d_array2)\n",
    "print('-------------')\n",
    "print( two_d_array3)\n",
    "print('-------------')\n",
    "print( two_d_array4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "e4691dbb-3e93-4c62-80e9-b87ad970da03",
   "metadata": {},
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "plt.rcParams['font.sans-serif']=['SimHei']#用来正常显示中文标签\n",
    "plt.rcParams['axes.unicode_minus'] = False# 显示负号"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "97424056-eb0e-42cd-8a82-75f4a1b52e8a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAABVoAAAEiCAYAAAAI+WlYAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAkcklEQVR4nO3df5SU9X0v8M8syy6/ESVKDJsAiraaUCIhh6SaorVWC0ipxaiJiVoa1CQmwdB7zTWh1hRIExO4vUSvJhWTaFKxEXJzNEIUUE+iRItEhRsNd7UoNRWVXQjswrJz/2jZhqJmZp7dffY783qdM3/M7rPzvNcz+97ZN+NMoVgsFgMAAAAAgIrV5R0AAAAAACB1hlYAAAAAgIwMrQAAAAAAGRlaAQAAAAAyMrQCAAAAAGRkaAUAAAAAyMjQCgAAAACQkaEVAAAAACAjQysAAAAAQEaG1ipx7rnnxrhx4/KOkdmLL74Yo0aNiueeey7vKAC9JvUO7+joiPnz58fRRx8dDQ0N8Xu/93vxyCOP5B0LoMel3t8REc8++2zMmzcvZs+eHZ///Odjx44deUcC6BXV0OG/6dOf/nRMnTo17xg1z9BaBTo6OmLdunXR3NwcW7duzTtOxVpbW+O8886LX/3qV3lHAeg11dDhCxYsiGXLlsWcOXPi5ptvjs7Ozpg2bVq0tLTkHQ2gx1RDfz/zzDPxnve8J7Zu3Rrjx4+PO+64I97//vdHW1tb3tEAelQ1dPhv+slPfhJ///d/n3cMwtBaFR555JHYtWtXNDQ0xOrVq/OOU5EdO3bEaaedFp2dnXlHAehVqXf4zp07Y8mSJfGd73wnFi5cGJdcckncdddd8eqrr8batWvzjgfQY1Lv74iIq6++OmbOnBmrVq2KhQsXxrp16+LZZ5+NH//4x3lHA+hR1dDhB7W1tcVll10WQ4YMyTsKYWitCmvWrIlx48bFtGnTYs2aNXnHqcjTTz8dU6dOjdtvvz3vKAC9KvUOHzRoUDz44IPxZ3/2Z10fO+qooyIi4sCBA3nFAuhxqfd3RMT5558f119/fdf1Y445Jurr66O9vT3HVAA9rxo6/KAvfOELUSwW4/LLL887CmForQpr1qyJ008/PU4//fRYu3btYX/YjhkzJpYvXx4PP/xwnH766fHOd77zkM//9V//dUydOjV27twZl19+eYwaNSrWr1/f9fkDBw7E5z73uRg9enQMGTIkfv/3fz/++Z//uevzJ554YnziE5845Db/8i//Mt7znveU/D2cdtppsXTp0ujfv3853zpA8lLv8IaGhpg0adIhH7v33nujrq4upkyZUtJtAKQo9f6OiLj44ovjHe94R9f1r371qzFo0KA444wzSr4NgBRVQ4dHRPzsZz+LpUuXxvLly2PgwIFlfS09w9CauJaWltiwYUNMnTq164d8w4YNhx33k5/8JP70T/80Jk+eHH/1V3912Of37dsXZ5xxRmzfvj2uvfbaOP7447s+t3jx4li6dGksWrQo7rnnnhg1alTMnj276/MXX3xxrFixoquY9u/fH9///vfjIx/5SMnfR12duyJQe6qlw/9rli9+8Ysxe/bseNvb3lbRbQD0ddXW3ytXrox3v/vdcd1118UPf/jDGDFiRNm3AZCKaunwffv2xaWXXhqf+tSn4n3ve185/wnoSUWSdvfddxcjorht27ZiZ2dnceTIkcXrrrvukGPe8Y53FBsaGoqPPvro697GggULihFR/NSnPvW6n7/nnnuKP/rRj7qu33nnncWIKP7qV78qFovFYnNzc7FQKHQdc8899xT79+9f/Ld/+7eyv5/m5uZiR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O3fujCOOOCLvWG/o+uuvj8mTJ8e0adPyjgI9Rn/3vhT7OyKtDtff1Aod3vtS7PCU+jtCh1Mb9HfvS7G/I9Lq8L7W30kPrUceeWQ89dRTh3xs165d0dDQkFOi6tbc3BwXXnhhLFu2LE466aS84/xW69evjx/+8Ifx5S9/OSIiGhoaolAoRF1d334i9x133BEvv/xyV4nt2bMn7rzzztiwYUN8/etfzzccdBP93btS6++INDtcf1MrdHjvSq3DU+zvCB1ObdDfvSu1/o5Is8P7Wn8nPbROnjw5brnllq7rzc3N0d7eHkceeWSOqarT3r17Y/r06TFz5syYNWtW7N69OyIiBg8eHIVCIed0r++EE06Im2++OcaPHx/nnHNOXHvttXHWWWfFsGHD8o72ph566KHo6Ojouv7Zz342pkyZ4oX4qSr6u/ek2N8RaXa4/qZW6PDek2KHp9jfETqc2qC/e0+K/R2RZof3tf7uu5N0CT7wgQ9Ea2tr3HrrrRERsXDhwjjzzDOjX79+OSerPqtXr47NmzfHLbfcEkOHDu26PP/883lHe0Nvfetb46677oqlS5fGySefHHv27EninfJGjx4dY8aM6boMGTIkRo4cGSNHjsw7GnQb/d17UuzviDQ7XH9TK3R470mxw1Ps7wgdTm3Q370nxf6OSLPD+1p/F4rFYjGXM3eTH/zgB3HhhRfGwIEDo66uLtatW5fMU7IBapn+BkiXDgdIk/6GnpX80BoR8dJLL8Xjjz8eU6ZMiaOOOirvOACUSH8DpEuHA6RJf0PPqYqhFQAAAAAgT0m/RisAAAAAQF9gaAUAAAAAyMjQCgAAAACQkaEVAAAAACAjQysAAAAAQEaGVgAAAACAjAytAAAAAAAZGVoBAAAAADIytAIAAAAAZPT/AZFD8M70n+hMAAAAAElFTkSuQmCC",
      "text/plain": [
       "<Figure size 1500x300 with 4 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 创建一个包含四个子图的图形，设置布局为一行四列\n",
    "fig, axes = plt.subplots(1, 4, figsize=(15, 3))\n",
    "\n",
    "# 在每个子图中显示对应的二维数组\n",
    "axes[0].imshow(two_d_array1, cmap='viridis')\n",
    "axes[0].set_title('Array 1')\n",
    "axes[1].imshow(two_d_array2, cmap='viridis')\n",
    "axes[1].set_title('Array 2')\n",
    "axes[2].imshow(two_d_array3, cmap='viridis')\n",
    "axes[2].set_title('Array 3')\n",
    "axes[3].imshow(two_d_array4, cmap='viridis')\n",
    "axes[3].set_title('Array 4')\n",
    "\n",
    "# 调整子图之间的间距\n",
    "plt.tight_layout()\n",
    "\n",
    "# 显示图形\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "26d2d9fe-a767-408e-ae38-390393e6e301",
   "metadata": {},
   "source": [
    "## 4.使用四个二维数组生成三维数组\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "efa34efa-90c8-433c-8c39-5aa02fcfe624",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[[0.5045208  0.92406741 0.96117996 0.64262153 0.8715444 ]\n",
      "  [0.19496945 0.53084609 0.61899516 0.28123388 0.80624643]\n",
      "  [0.20431289 0.9510875  0.59896979 0.5517332  0.95782439]\n",
      "  [0.40131312 0.19812512 0.53569954 0.93270243 0.29443461]\n",
      "  [0.64162742 0.76089355 0.64056177 0.18410004 0.144533  ]]\n",
      "\n",
      " [[0.88570355 0.24957787 0.52456327 0.47611231 0.57243493]\n",
      "  [0.38154283 0.88163409 0.23039634 0.64221333 0.77179571]\n",
      "  [0.19243445 0.49167336 0.94127991 0.82090721 0.24489844]\n",
      "  [0.05282288 0.12174842 0.63030444 0.77534971 0.28120104]\n",
      "  [0.2435859  0.30837898 0.88005805 0.67591576 0.73206563]]\n",
      "\n",
      " [[0.03656448 0.67389344 0.28020756 0.82800927 0.78491985]\n",
      "  [0.87212139 0.86617527 0.13332178 0.35441264 0.57349556]\n",
      "  [0.49284138 0.85590938 0.93029303 0.10598924 0.17451217]\n",
      "  [0.09894279 0.68081876 0.7936022  0.53810265 0.95868372]\n",
      "  [0.13045689 0.25835348 0.03826828 0.66284047 0.81192704]]\n",
      "\n",
      " [[0.08686103 0.17896087 0.88516625 0.83477802 0.83730887]\n",
      "  [0.69518642 0.97015567 0.35355177 0.81568589 0.79617097]\n",
      "  [0.37924665 0.58746471 0.64707012 0.02160775 0.69610958]\n",
      "  [0.33332549 0.55916759 0.53474614 0.91756406 0.63706331]\n",
      "  [0.98207718 0.03414705 0.38032678 0.67348959 0.36610101]]]\n"
     ]
    }
   ],
   "source": [
    "three_d_array = np.stack((two_d_array1, two_d_array2, two_d_array3, two_d_array4), axis = 0)\n",
    "print(three_d_array)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8903d5f4-0921-4dc1-a1a7-5b9de1e2040a",
   "metadata": {},
   "source": [
    "--- "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e8832497-ec02-4735-b5f6-1bc9a2367486",
   "metadata": {},
   "source": [
    "## 5.设置仿射变换信息"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "5f32786d-c951-4c1f-b859-c28a14202973",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 设定简单的空间参考信息【地理坐标系，单位为度°】\n",
    "upper_left_x = 114.32291507720947  # 左上角x坐标 [度°]\n",
    "upper_left_y = 30.578888565037637  # 左上角y坐标 [度°]\n",
    "pixel_size_x = 0.0001043726735391  # x方向像元大小[度°]\n",
    "pixel_size_y = -0.0001043726735391  # y方向像元大小[度°]\n",
    "\n",
    "# 创建一个字典来模拟空间参考信息\n",
    "spatial_reference = {\n",
    "    \"upper_left_x\": upper_left_x,\n",
    "    \"upper_left_y\": upper_left_y,\n",
    "    \"pixel_size_x\": pixel_size_x,\n",
    "    \"pixel_size_y\": pixel_size_y\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "c8d809c2-5155-4132-a705-77bec0ac6900",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 将空间参考信息与三维数组关联起来，可以使用一个字典或者自定义类等方式\n",
    "# 这里简单使用一个字典来表示带有空间参考信息的遥感影像数据\n",
    "remote_sensing_image = {\n",
    "    \"data\": three_d_array,\n",
    "    \"spatial_reference\": spatial_reference\n",
    "}"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ac49a252-158f-4007-8b4b-31ef226bbcce",
   "metadata": {},
   "source": [
    "## 6.明确影像数据的shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "6609d8f5-ece6-4388-9ff8-ce01fad1dbb6",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 获取影像数据的维度、行数、列数\n",
    "bands = remote_sensing_image[\"data\"].shape[0]\n",
    "rows = remote_sensing_image[\"data\"].shape[1]\n",
    "cols = remote_sensing_image[\"data\"].shape[2]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9c4b3089-6bce-43b0-b8a3-0d4b85c003d3",
   "metadata": {},
   "source": [
    "## 7.创建TIFF文件"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "5aabc56e-5181-4acf-93ff-c622433a382e",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "d:\\GitHub\\py313Env\\.venv\\Lib\\site-packages\\osgeo\\gdal.py:312: FutureWarning: Neither gdal.UseExceptions() nor gdal.DontUseExceptions() has been explicitly called. In GDAL 4.0, exceptions will be enabled by default.\n",
      "  warnings.warn(\n"
     ]
    }
   ],
   "source": [
    "driver = gdal.GetDriverByName('GTiff')\n",
    "with driver.Create('data/simulated_RS_image.tif', cols, rows, bands, gdal.GDT_Float32) as out_tiff:\n",
    "    # 设置地理变换参数\n",
    "    # 参数意义（假设元组为(gt[0], gt[1], gt[2], gt[3], gt[4], gt[5])）\n",
    "    gt = (\n",
    "        \n",
    "        # gt[0]（upper_left_x）\n",
    "        # 这个参数表示影像左上角像元中心的x轴（通常是经度方向或者地图投影后的x坐标方向）地理坐标。\n",
    "        # 它是影像在地理空间中起始位置的x坐标值，确定了影像在水平方向上的起始位置。\n",
    "        remote_sensing_image[\"spatial_reference\"][\"upper_left_x\"],\n",
    "        \n",
    "        # gt[1]（pixel_size_x）\n",
    "        # 它代表x方向（水平方向）上的像元尺寸，也就是影像在x方向上的分辨率。其值为正数时，\n",
    "        # 表示从左向右（沿着行方向）像元坐标增加时，地理坐标也是增加的。\n",
    "        remote_sensing_image[\"spatial_reference\"][\"pixel_size_x\"],\n",
    "\n",
    "        # gt[2]（rotation_x）\n",
    "        # 这个参数用于描述影像在x方向上的旋转情况。在一般情况下，\n",
    "        # 对于非旋转的遥感影像（大多数常规遥感影像都是如此），这个值为0。\n",
    "        0,\n",
    "\n",
    "        # gt[3]（upper_left_y）\n",
    "        # 表示影像左上角像元中心的y轴（通常是纬度方向或者地图投影后的y坐标方向）地理坐标。\n",
    "        # 它确定了影像在垂直方向上的起始位置。\n",
    "        remote_sensing_image[\"spatial_reference\"][\"upper_left_y\"],\n",
    "\n",
    "        # gt[4]（rotation_y）\n",
    "        # 用于描述影像在y方向上的旋转情况。和gt[2]类似，在非旋转影像中一般为0。\n",
    "        # 当影像旋转时，它会参与到像元坐标与地理y坐标之间的转换计算中，\n",
    "        # 与旋转角度的三角函数关系有关。\n",
    "        0,\n",
    "\n",
    "        # gt[5]（pixel_size_y）\n",
    "        # 代表y方向（垂直方向）上的像元尺寸，即影像在y方向上的分辨率。\n",
    "        # 当值为正数时，表示从上向下（沿着列方向）像元坐标增加时，\n",
    "        # 地理坐标是减少的（这是因为在地理坐标系中，纬度是从赤道向两极递减的）。\n",
    "        remote_sensing_image[\"spatial_reference\"][\"pixel_size_y\"]\n",
    "    )\n",
    "    out_tiff.SetGeoTransform(gt)\n",
    "    # 设置空间参考系统，这里简单设置为WGS84【地理坐标系】\n",
    "    srs = osr.SpatialReference()\n",
    "    srs.ImportFromEPSG(4326)\n",
    "    out_tiff.SetProjection(srs.ExportToWkt())\n",
    "    # 将三维数组数据写入TIFF文件\n",
    "    for b in range(bands):\n",
    "        out_tiff.GetRasterBand(b + 1).WriteArray(remote_sensing_image[\"data\"][b])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e4b13c4c-cb66-4ff8-b628-01a106ab805d",
   "metadata": {},
   "source": [
    "## 8.查看生成的模拟数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "c3ce0b2b-7d45-4299-bf17-217aec3d62f1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AXIS[\"Latitude\",NORTH],AXIS[\"Longitude\",EAST],AUTHORITY[\"EPSG\",\"4326\"]]'"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "filename = r'data/simulated_RS_image.tif'\n",
    "dataset = gdal.Open(filename) #打开文件\n",
    "dataset.GetProjection() #坐标投影信息"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "36a028ed-6fdf-4b0a-9d3a-3b99991bb381",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(4, 5, 5)"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dataset.ReadAsArray().shape #栅格形状信息[波段数，行，列]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "4e2e3606-f68d-462a-aaec-77c4c7d3d045",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(114.32291507720947,\n",
       " 0.0001043726735391,\n",
       " 0.0,\n",
       " 30.578888565037637,\n",
       " 0.0,\n",
       " -0.0001043726735391)"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dataset.GetGeoTransform() #仿射变换信息"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "43e78163-3bf5-4cbb-b4ad-9beb55bdabb5",
   "metadata": {},
   "source": [
    "## 9.读一个投影坐标系的影像查看属性"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "89e7aaac-eb5d-4129-83be-50475bbb930c",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "d:\\GitHub\\py313Env\\.venv\\Lib\\site-packages\\osgeo\\gdal.py:312: FutureWarning: Neither gdal.UseExceptions() nor gdal.DontUseExceptions() has been explicitly called. In GDAL 4.0, exceptions will be enabled by default.\n",
      "  warnings.warn(\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'PROJCS[\"WGS 84 / UTM zone 51N\",GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4326\"]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"latitude_of_origin\",0],PARAMETER[\"central_meridian\",123],PARAMETER[\"scale_factor\",0.9996],PARAMETER[\"false_easting\",500000],PARAMETER[\"false_northing\",0],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],AXIS[\"Easting\",EAST],AXIS[\"Northing\",NORTH],AUTHORITY[\"EPSG\",\"32651\"]]'"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "filename = r'data/S2_20190727San.tif'\n",
    "dataset = gdal.Open(filename) #打开文件\n",
    "dataset.GetProjection() #坐标投影信息"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "5f184812-bc44-4957-82f7-60d9b02c5280",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(-515060.0, 10.0, 0.0, 3396420.0, 0.0, -10.0)"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dataset.GetGeoTransform() #仿射变换信息"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3f5b7fb3-e567-4e55-bd7b-bdbafd05cb09",
   "metadata": {},
   "source": [
    "--- \n",
    "\n",
    "## 从普通的图片到遥感影像需要什么？\n",
    "使用Python GDAL生成一幅遥感影像通常需要以下几个关键参数及其具体信息：\n",
    "\n",
    "### 1. 驱动类型（Driver）\n",
    "- **具体信息**：\n",
    "    - GDAL使用驱动来处理不同格式的地理空间数据文件。对于生成遥感影像，需指定对应驱动。常见的GeoTIFF格式驱动名称是`'GTiff'`，通过`gdal.GetDriverByName()`函数来获取驱动对象。不同的驱动支持不同的文件格式，如`'HFA'`用于Erdas Imagine文件格式，`'ENVI'`用于ENVI遥感影像格式等。选择正确的驱动是确保生成的影像能被正确识别和后续处理的基础。\n",
    "\n",
    "### 2. 影像尺寸（Columns和Rows）\n",
    "- **具体信息**：\n",
    "    - `Columns`（列数）和`Rows`（行数）定义了遥感影像的空间范围大小。它们决定了影像在水平（x轴）和垂直（y轴）方向上包含的像元数量。像元是遥感影像的基本单元，行列数确定了像元的分布范围。例如，一个影像有100列和100行，那么它总共包含100×100 = 10000个像元。\n",
    "\n",
    "### 3. 波段数（Bands）\n",
    "- **具体信息**：\n",
    "    - 波段是遥感影像的一个重要概念，不同波段记录了不同的电磁辐射信息。例如，多光谱遥感影像可能包含红、绿、蓝等多个波段，每个波段对应不同的波长范围。波段数决定了影像在光谱维度上的信息丰富程度。可以根据实际需求生成单波段（如全色影像）或多波段（如彩色合成影像）的遥感影像。例如，常见的RGB彩色影像有3个波段，分别对应红、绿、蓝。\n",
    "\n",
    "### 4. 数据类型（Data Type）\n",
    "- **具体信息**：\n",
    "    - GDAL支持多种数据类型来存储像元值，如字节型（`gdal.GDT_Byte`）、整型（`gdal.GDT_Int16`、`gdal.GDT_Int32`）、浮点型（`gdal.GDT_Float32`、`gdal.GDT_Float64`）等。数据类型决定了每个像元能够存储的数据范围和精度。例如，`gdal.GDT_Byte`数据类型的像元值范围是0 - 255，适合存储无符号的8位图像数据，如一般的彩色图像；而`gdal.GDT_Float32`可以存储带有小数的数值，适合存储一些经过处理的、需要高精度的遥感数据，如地形高程数据等。\n",
    "\n",
    "### 5. 地理变换信息（Geo - Transform）\n",
    "- **具体信息**：\n",
    "    - 地理变换信息是一个包含6个参数的元组，通常表示为`(upper_left_x, pixel_size_x, rotation_x, upper_left_y, rotation_y, pixel_size_y)`。\n",
    "    - `upper_left_x`和`upper_left_y`是影像左上角像元中心的地理坐标（经度和纬度或其他地理坐标系下的坐标）。`pixel_size_x`和`pixel_size_y`分别是x方向和y方向的像元尺寸（单位通常与地理坐标相同，如度或米）。`rotation_x`和`rotation_y`用于定义影像的旋转情况，在一般非旋转的遥感影像中通常为0。这些参数将影像的像元坐标与实际的地理坐标建立起联系，使得影像能够在地理空间中正确定位。\n",
    "\n",
    "### 6. 空间参考系统（Spatial Reference）\n",
    "- **具体信息**：\n",
    "    - 空间参考系统定义了遥感影像所使用的地理坐标系，如WGS84（`EPSG:4326`）是一种常见的地理坐标系，用于全球定位。它确保影像在地理空间中的位置和方向能够与其他地理数据进行准确的匹配和整合。通过`osr.SpatialReference`类来定义和处理空间参考系统，可以从预定义的EPSG代码导入，也可以自定义投影参数。\n",
    "\n",
    "### 像元值参数\n",
    "在上述提到的参数中，像元值参数实际上是通过“数据类型（Data Type）”参数来间接确定的。当你确定了数据类型后，每个像元所能存储的值的范围和精度就随之确定了。\n",
    "\n",
    "例如，若选择`gdal.GDT_Byte`作为数据类型，那么每个像元的值就只能在0 - 255这个范围内（因为这是无符号8位数据的取值范围），并且只能是整数。而如果选择`gdal.GDT_Float32`作为数据类型，像元值就可以是带有小数的数值，范围则根据浮点数的表示范围来确定（通常是 -3.4028234663852886×10^38 到 3.4028234663852886×10^38 左右）。\n",
    "\n",
    "在实际生成遥感影像时，你需要根据影像所代表的具体内容和后续处理需求来选择合适的数据类型以确定像元值的存储方式。同时，你还需要为每个像元赋予具体的值，这通常是通过创建一个与影像尺寸（行列数）和波段数相匹配的多维数组（如使用`numpy`库创建）来实现的，然后将这个数组中的数据写入到生成的影像文件中。例如，你可以创建一个形状为`(bands, rows, cols)`的数组，其中`bands`是波段数，`rows`是行数，`cols`是列数，数组中的每个元素就是对应位置像元的值。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d8410730-9f37-4004-b8ea-fe69a2e1097c",
   "metadata": {},
   "source": [
    "## 10米分辨率 在epsg 4326 地理坐标系中与度的换算\n",
    "\n",
    "1. **理解分辨率和地理坐标系的关系**\n",
    "   - 在地理坐标系（如EPSG 4326，即WGS84坐标系）中，坐标单位是度（°），而分辨率通常是指在空间数据（如遥感影像等）中每个像元所代表的实际地面距离。\n",
    "   - 地球近似为一个球体，赤道周长约为40075000米，经度一圈是360°，所以在赤道处，1°经度对应的地面距离约为40075000÷360≈111320米。纬度对应的距离随着纬度的升高而减小，因为纬线周长从赤道向两极递减，1°纬度在赤道处对应的距离约为110574米（计算方法为：地球子午线周长约40008000米，360°，1°纬度约为40008000÷360≈110574米）。\n",
    "\n",
    "2. **计算10米分辨率对应的度数**\n",
    "   - **经度方向（东西方向）**：\n",
    "     - 在赤道上，1°经度约为111320米，那么10米对应的经度度数约为10÷111320≈0.0000898°（或约为0.0000898×3600≈3.23″，1° = 3600″）。\n",
    "   - **纬度方向（南北方向）**：\n",
    "     - 在赤道上，1°纬度约为110574米，10米对应的纬度度数约为10÷110574≈0.0000904°（或约为0.0000904×3600≈3.25″）。\n",
    "\n",
    "需要注意的是，这是在赤道附近的近似计算。随着纬度的增加，纬度方向上1°对应的实际距离会减小，所以10米分辨率对应的纬度度数会增加。如果要更精确地计算在不同纬度处的度数，需要考虑地球的椭圆形状以及更复杂的几何关系。"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.13.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
